#@head() #@header()
<title>融资需求管理</title>
#@aside("marketing")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
			<ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">新增短信</a></li>
              <!--<li class="active"><a href="#tab_2" data-toggle="tab" aria-expanded="false">还款管理</a></li>-->
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
				 <div class="box-body" style="width:50%">
					<table id="example1" class="table table-bordered table-striped dataTable col-md-8" role="grid" aria-describedby="example1_info">
						<tbody>
						<tr role="row" class="odd">
						  <td align="right" style="width:130px;" class="sorting_1">短信内容</td>
						  <td class="sorting_1">
							<textarea id="contents" rows="10" cols="80"></textarea>
						  </td>
						</tr>
						<tr role="row" class="odd">
						  <td align="right" style="width:130px;" class="sorting_1">发放对象</td>
						  <td  class="sorting_1">
							<select id="messagetype" class="form-control">
								<option value="all">全部用户</option>
								<option value="multiple">指定用户</option>
								<option value="sql">自定义</option>
							</select>
						  </td>
						</tr>
						<tr role="row" id="zd_user" hidden class="odd">
						  <td align="right" style="width:130px;" class="sorting_1">指定用户</td>
						  <td  class="sorting_1">
							<textarea id="summary1" rows="5" cols="80"></textarea>
						  </td>
						</tr>
						<tr role="row" id="zdy_user" hidden class="odd">
						  <td align="right" style="width:130px;" class="sorting_1">自定义SQL</td>
						  <td  class="sorting_1">
							<textarea id="summary2" rows="5" cols="80"></textarea>
						  </td>
						</tr>
						</tbody>
					</table>
				</div>
				<button type="button" id="submitbt" class="btn bg-olive margin">提交</button>
              </div>
            </div>
            <!-- /.tab-content -->
          </div>
		  
	</section>
</div>
#@footer()
<script>
	$("#messagetype").change(function(){
		if($("#messagetype").val()=="all"){
			$("#zd_user").hide();
			$("#zdy_user").hide();
		}else if($("#messagetype").val()=="multiple"){
			$("#zd_user").show();
			$("#zdy_user").hide();
		}else if($("#messagetype").val()=="sql"){
			$("#zd_user").hide();
			$("#zdy_user").show();
		}
	});
	$("#submitbt").click(function(){
		var contents = $("#contents").val();
		var messagetype = $("#messagetype").val();
		if($("#messagetype").val()=="all"){
			var summary = "";
		}else if($("#messagetype").val()=="multiple"){
			var summary = $("#summary1").val();
		}else if($("#messagetype").val()=="sql"){
			var summary = $("#summary2").val();
		} 
		layer.confirm('确认发送短信息？', {
		  btn: ['确认','取消'] //按钮
		}, function(){
			layer.msg('发送中',function(){
				console.log(contents,messagetype,summary); 
				$.getJSON("/smsLog/mass?token=#(session.token??)&contents="+contents+"&type="+messagetype+"&summary="+summary, function(setmessageinfo) {
					if(setmessageinfo.code=='success'){
						layer.msg(setmessageinfo.msg, {icon:1},function(){
							location.href="#(path)/admin/page/marketing-setmessage"
						}); 
					}else if(setmessageinfo.code=='error'){
						layer.msg(setmessageinfo.msg, {icon : 2});
					}
				});	
			});
		}, function(){
			layer.msg('已取消', {icon: 2});
		});	
	});
</script> 

</body>
</html>

